$(function() {
	var setting = {
		data : {
			simpleData : {
				enable : true
			}
		}
	};

	$.fn.zTree.init($("#cate-tree"), setting, treeNodes);

	$('#btn-cate-select').click(function() {
		$('#cate-tree-modal').modal('show');
	});

	$('#btn-close-form').click(function() {
		$('#cate-tree-modal').modal('hide');
	});

	$('#btn-done').click(function() {
		var treeObj = $.fn.zTree.getZTreeObj("cate-tree");
		var nodes = treeObj.getSelectedNodes();
		if(nodes.length) {
			var node = nodes[0];
			$('#category').val(node.cate);
			$('#cname').val(node.name);
		} else {
			$('#category').val('');
			$('#cname').val('');
		}
		$('#cate-tree-modal').modal('hide');
		return false;
	});
	$('#btn-selectall').click(function() {
		$('#page-list').uiTable('selectAll');
	});
	$('.edit-page').click(function() {
		var me = $(this), title = '编辑网页【' + me.attr('data-content') + '】', id = me.attr('id');
		openTab(me.attr('href'), id, title, 'icon_editor');
		return false;
	});
	$('#page-dropdown-menu').delegate('a', 'click', function() {
		var me = $(this), href = me.attr('href'), ids = $('#page-list').uiTable('selected');
		if(ids.length == 0) {
			alert('请选择要处理的网页.');
			return false;
		}
		ids = ids.join(',');
		if(me.hasClass('delete') && !confirm('网页被删除后将不能恢复，你确定要删除吗?')) {
			return false;
		}
		window.location.href = href + '&pid=' + ids;
		return false;
	});
});
